﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace LoginDAS
{
   public class Login
    {
        #region Fiellds
        ebird.QueryGenerics.QueryGenerics queryGenerics;
        #endregion

        #region Constructor
        public Login(string connectionString)
        {
            queryGenerics = new ebird.QueryGenerics.QueryGenerics(connectionString);
        }
        #endregion
       

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="dsLogin"></param>
        /// <remarks>
        /// This function checks the database table with the given username and password and if there is match ,ie
        /// if such user exists,it will return true.Otherwise false is returned.The dataset dsLogin will contain 
        /// the details of user such as name,type etc..         
        /// </remarks>
        /// <returns></returns>
        public bool ValidateLogin(string userName, string password, out DataSet dsLogin)
        {
            SqlDataAdapter sqlAdapter= queryGenerics.SQLDataAdapter();
            dsLogin = new DataSet();
            sqlAdapter.SelectCommand.CommandText = "SELECT UD.UD_UserPersonalID,UD.UD_FirstName,US.US_GroupID,US.US_GroupName " +
            "from UserList as UL,UserDetails as UD,UserGroup as US,UserGroupMap as UR  where  UL.UL_UserPersonalID " +
            "= UD.UD_UserPersonalID and UD.UD_UserPersonalID = UR.UR_UserID and  UR.UR_UserGroupID = US.US_GroupID " +
            "and UL_UserName =  '" + userName + "' and UL_Password = '" + password + "'";

            sqlAdapter.Fill(dsLogin);
            if (dsLogin.Tables[0].Rows.Count > 0)
                return true;
            else
                return false;

        }
    }
}
